package com.netx.cubigraf.servlets;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.netx.generics.sql.Table;
import com.netx.data.Connection;
import com.netx.data.DatabaseException;
import com.netx.ebs.EbsRequest;
import com.netx.ebs.EbsResponse;
import com.netx.ebs.TemplateValues;


public class SrvServicoVerProcurar extends CubigrafServlet {

	public SrvServicoVerProcurar() {
		super("servico-ver");
	}
	
	public void doGet(EbsRequest request, EbsResponse response) throws IOException, DatabaseException {
		response.sendDisableCache();
		response.setContentType("text/html");
		TemplateValues tv = new TemplateValues();

		Connection c = request.getDatabaseConnection();
		Table desenhadores = c.select("users.user_id, users.name FROM users, roles WHERE users.role_id=roles.role_id AND (roles.name='Desenhador' OR roles.name='Gestor') ORDER BY users.name");
		List<TemplateValues> dData = new ArrayList<TemplateValues>();
		for(int i=0; i<desenhadores.getRowCount(); i++) {
			TemplateValues tvDd = new TemplateValues();
			tvDd.put("codigo", desenhadores.getString(1, i));
			tvDd.put("nome", CubigrafUtils.getFirstName(desenhadores.getString(2, i)), true);
			dData.add(tvDd);
		}
		tv.putList("desenhadores", dData);
		response.sendTemplate("servico-ver.procurar.tplt", tv);
	}

}
